<template>
  <view class="">
    <view >
     <image style="width: 586rpx;width: 496rpx;margin-top: 120rpx;margin-left: 108rpx;" src="https://img.wilmer.com.cn/bank/top.png"></image>
    </view>
    <view class="login-form-content">
      <view class="lg-button">
        <button open-type="getPhoneNumber" @tap="logCode" @getphonenumber="getPhoneNumber"  class="login-btn cu-btn block bg-blue lg round">手机号快捷登录</button>
      </view>
      <view class="reg text-center" v-if="register">
        <text class="text-grey1">没有账号？</text>
        <text @click="handleUserRegister" class="text-blue">立即注册</text>
      </view>
      <view class="lg_btn">
        <text class="text-grey1">登录即代表同意</text>
        <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
        <text @click="handlePrivacy" class="text-blue"></text>
		<text class="text-grey1">未验证的手机号验证后会自动创建账号</text>
      </view>
    </view>
	
	<view>	
	<view class="about"></view>
		<image style="width: 100%;height: 222rpx;position: fixed;left: 0;bottom: 0;" src="https://img.wilmer.com.cn/bank/bt.png"></image>
		<image style="width: 156rpx;height: 34rpx;position: fixed;left: 298rpx;bottom: 120rpx;" src="https://img.wilmer.com.cn/bank/about.png"></image>
	</view>
     
  </view>
</template>

<script>
  import { getCodeImg,wechatLogin } from '@/api/login'

  export default {
    data() {
      return {
        globalConfig: getApp().globalData.config,
        loginForm: {
          loginCode: "",
		  phoneCode:""
        }
      }
    },
    created() {
    },
    methods: {
      // 隐私协议
      handlePrivacy() {
        let site = this.globalConfig.appInfo.agreements[0]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
      // 用户协议
      handleUserAgrement() {
        let site = this.globalConfig.appInfo.agreements[1]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
	  //获取用户的code
	  logCode() {
	  	var that = this
	  	uni.login({
	  		"provider": "weixin",
	  		success(res) {
	  			that.loginForm.loginCode = res.code
	  		}
	  	})
	  },
	  
	  getPhoneNumber(e) {
		 this.loginForm.phoneCode=e.detail.code
	     this.wechatLogin()
	  },

      // 一键登录
      async wechatLogin() {
		this.$modal.loading("登录中，请耐心等待...")
        this.$store.dispatch('wechatLogin', this.loginForm).then(() => {
          this.$modal.closeLoading()
          this.loginSuccess()
        }).catch(() => {
          
        })
      },
      // 登录成功后，处理函数
      loginSuccess(result) {
        // 设置用户信息
        this.$store.dispatch('GetInfo').then(res => {
          this.$tab.reLaunch('/pages/index')
        })
      }
    }
  }
</script>

<style lang="scss">
   .about{
		display: flex;
		justify-content: center;
	}
  page {
    background-color: #ffffff;
  }
  .lg-button{
	  margin-top: 60rpx;
	  padding: 32rpx;
  }
  .lg_btn{
	  padding-left: 60rpx;
	  padding-right: 60rpx;
	  
  }

  .normal-login-container {
    width: 100%;

    .logo-content {
      width: 100%;
      font-size: 21px;
      text-align: center;
      padding-top: 15%;

      image {
        border-radius: 4px;
      }

      .title {
        margin-left: 10px;
      }
    }

    .login-form-content {
      text-align: center;
      margin: 20px auto;
      margin-top: 15%;
      width: 80%;

      .input-item {
        margin: 20px auto;
        background-color: #f5f6f7;
        height: 45px;
        border-radius: 20px;

        .icon {
          font-size: 38rpx;
          margin-left: 10px;
          color: #999;
        }

        .input {
          width: 100%;
          font-size: 14px;
          line-height: 20px;
          text-align: left;
          padding-left: 15px;
        }

      }

      .login-btn {
        margin-top: 40px;
        height: 45px;
      }
      
      .reg {
        margin-top: 15px;
      }
      
      .xieyi {
        color: #333;
        margin-top: 20px;
      }
      
      .login-code {
        height: 38px;
        float: right;
      
        .login-code-img {
          height: 38px;
          position: absolute;
          margin-left: 10px;
          width: 200rpx;
        }
      }
    }
  }

</style>
